unit EditRakes;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Buttons, ExtCtrls, StdCtrls, umainutils, Oracle, uSQLs, uUtils, gnugettext;

type
  TuFrmEditRakes = class(TForm)
    edt_Name: TLabeledEdit;
    pnl_Buttons: TPanel;
    btn_Save: TSpeedButton;
    btn_Close: TSpeedButton;
    OracleQuery1: TOracleQuery;
    procedure btn_SaveClick(Sender: TObject);
    procedure FormKeyPress(Sender: TObject; var Key: Char);
    procedure btn_CloseClick(Sender: TObject);
  private
    { Private declarations }
    m_IsClone, m_IsEdit: boolean;
    m_recordID: string;
  public
    procedure ShowForm(IsEdit, IsClone: boolean; recordID: string);
    { Public declarations }
  end;

var
  uFrmEditRakes: TuFrmEditRakes;

implementation

uses UfrmMain;
{$R *.dfm}
{ TuFrmEditCountries }

procedure TuFrmEditRakes.btn_CloseClick(Sender: TObject);
begin
  close();
end;

procedure TuFrmEditRakes.btn_SaveClick(Sender: TObject);
begin
  if m_IsClone or (not m_IsEdit) then
  begin
    InsertDataIntoDB('RAKES', 'NAME', '''' + edt_Name.Text + '''');
  end
  else
  begin
    UpdateDataToDB('RAKES', 'NAME=''' + edt_Name.Text + '''', 'ID=' + m_recordID);
  end;
  FrmMain.GetGridData(FrmMain.stg_Rakes, SQL_Rakes, false);
    FrmMain.stg_RakesSelectCell(self, 0, FrmMain.stg_Rakes.Row, canselect);
  close();
end;

procedure TuFrmEditRakes.FormKeyPress(Sender: TObject; var Key: Char);
begin
  // The Escape key is #27.
  if Key = #27 then
    close
  else if Key = #13 then
    btn_Save.Click;
end;

procedure TuFrmEditRakes.ShowForm(IsEdit, IsClone: boolean; recordID: string);
var
  Query: string;
begin
  m_IsClone := IsClone;
  m_IsEdit := IsEdit;
  m_recordID := recordID;
  OracleQuery1.Session := FrmMain.OracleSession1;
  edt_Name.Text := '';
  if IsEdit then
  begin
    Query := 'select NAME from RAKES where id=' + recordID;
    OracleQuery1.SQL.Clear;
    OracleQuery1.SQL.Text := (Query);
    OracleQuery1.Execute;
    edt_Name.Text := OracleQuery1.Field('NAME');
  end;
  ShowModal();
end;

end.
